import urllib
import urllib.request

def get_image(url):
    # 先把图片写入内存中
    request=urllib.request.Request(url)
    response=urllib.request.urlopen(request)
    # 读取字节流
    get_img_code=response.read()

    # 处理图片名字
    url_split= url.split("/")

    # 新建图片文件
    file=open('C:\\Users\\Administrator\\Desktop\\'+url_split[-1],'wb')
    file.write(get_img_code)
    file.close()


url="http://n.sinaimg.cn/news/crawl/117/w550h367/20220417/a3a9-08b2ca6dffe4210149dda424adf0734f.jpg"
get_image(url)
